%-------------------------------------------------------------------------------
% JPEG Image Processing
%-------------------------------------------------------------------------------
% Arguments: jpgFile (string)   default='Pic.jpg'
%            plotMode (int)     1 = single Gray scale image (default)
%                               2 = side-by-side RGB and Gray scale images
%            numRows (int)      
%            numCols (int)      
%-------------------------------------------------------------------------------
function procImage(jpgFile, plotMode, numRows, numCols)
if nargin < 1
  jpgFile = 'Pic.jpg';
end
if nargin < 2
  plotMode = 1;
end
if nargin < 4
  numRows = 256; numCols = 256;  
end

picRGB = imread(jpgFile);  % read in the image file

imageDim = [numRows, numCols];

% scale the RGB image - keep this around just for reference
picRGBResized = imresize(picRGB, imageDim, 'bicubic', 'Antialiasing', true);
                         
% convert RGB image Gray scale
picGrayResized = rgb2gray(picRGBResized);

if plotMode == 2 
   subplot(1,2,1);
   image(picRGBResized); 
   axis equal; 

   subplot(1,2,2);
   image(picGrayResized); 
   colormap gray(256); 
   axis equal; 
else 
   image(picGrayResized);   
   colormap gray(256);    
   axis equal;    
end



